A minimal collection of most wanted and widely accepted idioms and coding conventions for C++ development presented with examples and explanations. The lecture targets performance oriented codes so emphasis is on performance-friendly techiques.
Topics covered:
1) Design issues: idioms and best practices
- Resource Aquisition Is Initialization (RAII)
- Ownership semantics and smart pointers
- Header files: dependencies and decoupling
2) Objects Construction/Destruction/Copying
- Designing constructors
- Rule Of Three
- Transactional programming
3) Namespaces
- ADL/Koenig Lookup
4) Static analyzers
Introduction to Lisp. A survey of lisp's history, current incarnations and advanced features such as list comprehensions, macros and domain-specific-language [DSL] support.
LISP Language, LISP Introduction, List Processing, LISP Syntax, Lisp Comparison Structures, Lisp Applications. Using of LISP language in Artificial Intelligence
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
If virtual functions in C++ imply design patterns, then C++ lambdas imply what? What does it really mean to have lambdas in C++? Frankly, I don't know but I've a hunch: It's BIG.
Just like virtual functions open doors to the OO paradigm, lambdas open doors to a different paradigm--the functional paradigm. This talk is not a praise of functional programming or some elusive lambda-based library. (Although, I'll mention one briefly that tops my list these days.) Instead, the goal is to have fun while working our way through some mind-bending examples of C++14 lambdas. Beware, your brain will hurt! Bring your laptop and code the examples right along because that may be the fastest way to answer the quiz.
The Design of the Scalaz 8 Effect SystemJohn De Goes
Purely functional Scala code needs something like Haskell's IO monad—a construct that allows functional programs to interact with external, effectful systems in a referentially transparent way. To date, most effect systems for Scala have fallen into one of two categories: pure, but slow or inexpressive; or fast and expressive, but impure and unprincipled. In this talk, John A. De Goes, the architect of Scalaz 8’s new effect system, introduces a novel solution that’s up to 100x faster than Future and Cats Effect, in a principled, modular design that ships with all the powerful primitives necessary for building complex, real-world, high-performance, concurrent functional programs.
Thanks to built-in concurrency, high performance, lawful semantics, and rich expressivity, Scalaz 8's effect system may just be the effect system to attract the mainstream Scala developers who aren't familiar with functional programming.
C++20 comes with some big new language features: modules, coroutines, concepts, spaceship, and many new libraries. But apart from all those, C++20 also offers many small language improvements, making C++ more powerful and expressive, but also safer and more consistent. This talk is an overview over all those smaller additions to the core language that will make your life easier. We will discuss much-needed improvements to existing facilities such as lambdas, CTAD, structured bindings, and initialisation, as well as brand-new language utilities that you may not yet have heard about!
The presentation shows major features of the new C++ standard (language and the library). The full list of new things is very broad, so I've categorized them to be easier to understand.
Computer Vision using Ruby and libJIT - RubyConf 2009Jan Wedekind
Ruby originated in Japan, the country which is world-leading in robotic research. It suggests itself to put the two together and to start using Ruby as a language to program robots. However at the moment the performance of available Ruby interpreters is not sufficient. It is hard to achieve performance comparable to compiled C++-code since manipulation of Ruby-integers and Ruby-arrays requires frequent bounds-checking. It can be shown that universal bounds-check elimination is actually impossible.
Some notes about programming in Scala: it covers Scala syntax and semantics, programming techniques, idioms, patterns. Many Scala features are introduced, from basic to intermediate and advanced. These are not introductory notes, but they assume a working knowledge with some other programming language (Java, C#, C++), object-oriented programming (OOP) concepts, and functional programming (FP) concepts.
A minimal collection of most wanted and widely accepted idioms and coding conventions for C++ development presented with examples and explanations. The lecture targets performance oriented codes so emphasis is on performance-friendly techiques.
Topics covered:
1) Design issues: idioms and best practices
- Resource Aquisition Is Initialization (RAII)
- Ownership semantics and smart pointers
- Header files: dependencies and decoupling
2) Objects Construction/Destruction/Copying
- Designing constructors
- Rule Of Three
- Transactional programming
3) Namespaces
- ADL/Koenig Lookup
4) Static analyzers
Introduction to Lisp. A survey of lisp's history, current incarnations and advanced features such as list comprehensions, macros and domain-specific-language [DSL] support.
LISP Language, LISP Introduction, List Processing, LISP Syntax, Lisp Comparison Structures, Lisp Applications. Using of LISP language in Artificial Intelligence
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
If virtual functions in C++ imply design patterns, then C++ lambdas imply what? What does it really mean to have lambdas in C++? Frankly, I don't know but I've a hunch: It's BIG.
Just like virtual functions open doors to the OO paradigm, lambdas open doors to a different paradigm--the functional paradigm. This talk is not a praise of functional programming or some elusive lambda-based library. (Although, I'll mention one briefly that tops my list these days.) Instead, the goal is to have fun while working our way through some mind-bending examples of C++14 lambdas. Beware, your brain will hurt! Bring your laptop and code the examples right along because that may be the fastest way to answer the quiz.
The Design of the Scalaz 8 Effect SystemJohn De Goes
Purely functional Scala code needs something like Haskell's IO monad—a construct that allows functional programs to interact with external, effectful systems in a referentially transparent way. To date, most effect systems for Scala have fallen into one of two categories: pure, but slow or inexpressive; or fast and expressive, but impure and unprincipled. In this talk, John A. De Goes, the architect of Scalaz 8’s new effect system, introduces a novel solution that’s up to 100x faster than Future and Cats Effect, in a principled, modular design that ships with all the powerful primitives necessary for building complex, real-world, high-performance, concurrent functional programs.
Thanks to built-in concurrency, high performance, lawful semantics, and rich expressivity, Scalaz 8's effect system may just be the effect system to attract the mainstream Scala developers who aren't familiar with functional programming.
C++20 comes with some big new language features: modules, coroutines, concepts, spaceship, and many new libraries. But apart from all those, C++20 also offers many small language improvements, making C++ more powerful and expressive, but also safer and more consistent. This talk is an overview over all those smaller additions to the core language that will make your life easier. We will discuss much-needed improvements to existing facilities such as lambdas, CTAD, structured bindings, and initialisation, as well as brand-new language utilities that you may not yet have heard about!
The presentation shows major features of the new C++ standard (language and the library). The full list of new things is very broad, so I've categorized them to be easier to understand.
Computer Vision using Ruby and libJIT - RubyConf 2009Jan Wedekind
Ruby originated in Japan, the country which is world-leading in robotic research. It suggests itself to put the two together and to start using Ruby as a language to program robots. However at the moment the performance of available Ruby interpreters is not sufficient. It is hard to achieve performance comparable to compiled C++-code since manipulation of Ruby-integers and Ruby-arrays requires frequent bounds-checking. It can be shown that universal bounds-check elimination is actually impossible.
Some notes about programming in Scala: it covers Scala syntax and semantics, programming techniques, idioms, patterns. Many Scala features are introduced, from basic to intermediate and advanced. These are not introductory notes, but they assume a working knowledge with some other programming language (Java, C#, C++), object-oriented programming (OOP) concepts, and functional programming (FP) concepts.
Presentation on native interfaces for the R programming language given as part of a course in advanced R programming at FHCRC:
https://secure.bioconductor.org/SeattleMay10/
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
This presentation takes a case-study based approach to design patterns. A purposefully simplified example of expression trees is used to explain how different design patterns can be used in practice. Examples are in C#, but is relevant for anyone who is from object oriented background.
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
Abstract: Chances are you code in a language that's either descended from C, inspired by C, or run in an interpreter that itself is written in C. Still... do you actually know how to code in C? Despite its long-standing position as a sort of "lingua franca", an agreed-upon common language, more and more developers are putting together successful, satisfying careers, without ever learning this seminal language. But what if you have to call into C code from your favorite scripting language, or use APIs like OpenGL that are written to be called from C? Many developers find C very challenging, particularly its manual memory-management and other low-level concerns. In this session, we'll show you why you shouldn't be afraid of C, how you can use the skills you already have from the languages you code in today, and how to master structs, enums, typedefs, malloc(), free(), and the rest of C's sharp edges. Examples will be from the point-of-view of the C-skewing iPhone SDK, but will be designed to be broadly applicable and platform-agnostic.
What's new in Apache SystemML - Declarative Machine LearningLuciano Resende
SystemML was designed with the main goal of lowering the complexity required to maintain and scale Machine Learning algorithms. It provides a declarative machine learning (DML) that simplify the specification of machine learning algorithms using an R-like and Python-like that significantly increases the productivity of data scientist as it provides flexibility on how the custom analytics are expressed and also provides data independence from the underlying input formats and physical custom analytics.
This presentation gives a quick introduction to Apache SystemML, provides an updated on the recent areas that are being developed by the project community, and go over a tutorial that enables one to quickly get up to speed in SystemML.
We have finished studying the patterns of 64-bit errors and the last thing we will speak about, concerning these errors, is in what ways they may occur in programs.
Machine learning in the enterprise is an iterative process. Data scientists will tweak or replace their learning algorithm in a small data sample until they find an approach that works for the business problem and then apply the Analytics to the full data set. Apache SystemML is a new system that accelerates this kind of exploratory algorithm development for large-scale machine learning problems. SystemML provides a high-level language to quickly implement and run machine learning algorithms on Spark. SystemML’s cost-based optimizer takes care of low-level decisions about how to use Spark’s parallelism, allowing users to focus on the algorithm and the real-world problem that the algorithm is trying to solve. This talk will introduce you to SystemML and get you started building declarative analytics with SystemML using a simple Zeppelin notebook and running on Apache Spark environment.
The Present and The Future of Functional Programming in C++Alexander Granin
Keynote talk for C++ Siberia 2019.
I'm speaking about why Functional Programming is important in C++ world, what is the philosophy of FP in C++, and what features do we have. I'm presenting a connection of constexpr and template metaprogramming to pure FP, and talking about why monads are inevitable. I'm also discussing an upcoming features in C++.
1. Rcpp: Seamless R and C++
Dirk Eddelbuettel Romain François
edd@debian.org romain@r-enthusiasts.com
useR! 2010, 21 July 2010, NIST, Gaithersburg, Maryland, USA
4. Background API Sugar Modules
Plat du jour
1 Appetizers : Some background on R and C++
2 Main course : The Rcpp API
3 Desert : Rcpp sugar
4 Coffee : Rcpp modules
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
5. Background API Sugar Modules Overview Examples
R support for C/C++
R is a C program
R supports C++ out of the box, just use a .cpp file extension
R exposes a API based on low level C functions and MACROS.
R provides several calling conventions to invoke compiled code.
SEXP foo( SEXP x1, SEXP x2 ){
...
}
R> .Call( "foo", 1:10, rnorm(10) )
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
6. Background API Sugar Modules Overview Examples
.Call example
#include <R.h>
#include <Rdefines.h>
extern "C" SEXP vectorfoo(SEXP a, SEXP b){
int i, n;
double *xa, *xb, *xab; SEXP ab;
PROTECT(a = AS_NUMERIC(a));
PROTECT(b = AS_NUMERIC(b));
n = LENGTH(a);
PROTECT(ab = NEW_NUMERIC(n));
xa=NUMERIC_POINTER(a); xb=NUMERIC_POINTER(b);
xab = NUMERIC_POINTER(ab);
double x = 0.0, y = 0.0 ;
for (i=0; i<n; i++) xab[i] = 0.0;
for (i=0; i<n; i++) {
x = xa[i]; y = xb[i];
res[i] = (x < y) ? x*x : -(y*y);
}
UNPROTECT(3);
return(ab);
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
7. Background API Sugar Modules Overview Examples
.Call example: character vectors
R> c( "foo", "bar" )
#include <R.h>
#include <Rdefines.h>
extern "C" SEXP foobar(){
SEXP res = PROTECT(allocVector(STRSXP, 2));
SET_STRING_ELT( res, 0, mkChar( "foo" ) ) ;
SET_STRING_ELT( res, 1, mkChar( "bar" ) ) ;
UNPROTECT(1) ;
return res ;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
8. Background API Sugar Modules Overview Examples
.Call example: calling an R function
R> eval( call( "rnorm", 3L, 10.0, 20.0 ) )
#include <R.h>
#include <Rdefines.h>
extern "C" SEXP callback(){
SEXP call = PROTECT( LCONS( install("rnorm"),
CONS( ScalarInteger( 3 ),
CONS( ScalarReal( 10.0 ),
CONS( ScalarReal( 20.0 ), R_NilValue )
)
)
) );
SEXP res = PROTECT(eval(call, R_GlobalEnv)) ;
UNPROTECT(2) ;
return res ;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
10. Background API Sugar Modules Overview Example Conversion
The Rcpp API
Encapsulation of R objects (SEXP) into C++ classes:
NumericVector, IntegerVector, ..., Function,
Environment, Language, ...
Conversion from R to C++ : as
Conversion from C++ to R : wrap
Interoperability with the Standard Template Library (STL)
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
11. Background API Sugar Modules Overview Example Conversion
The Rcpp API : classes
Rcpp class R typeof
Integer(Vector|Matrix) integer vectors and matrices
Numeric(Vector|Matrix) numeric ...
Logical(Vector|Matrix) logical ...
Character(Vector|Matrix) character ...
Raw(Vector|Matrix) raw ...
Complex(Vector|Matrix) complex ...
List list (aka generic vectors) ...
Expression(Vector|Matrix) expression ...
Environment environment
Function function
XPtr externalptr
Language language
S4 S4
... ...
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
12. Background API Sugar Modules Overview Example Conversion
The Rcpp API : example
SEXP foo( SEXP xs, SEXP ys ){
Rcpp::NumericVector xx(xs), yy(ys) ;
int n = xx.size() ;
Rcpp::NumericVector res( n ) ;
double x = 0.0, y = 0.0 ;
for (int i=0; i<n; i++) {
x = xx[i];
y = yy[i];
res[i] = (x < y) ? x*x : -(y*y);
}
return res ;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
13. Background API Sugar Modules Overview Example Conversion
The Rcpp API : example
using namespace Rcpp ;
SEXP bar(){
std::vector<double> z(10) ;
List res = List::create(
_["foo"] = NumericVector::create(1,2),
_["bar"] = 3,
_["bla"] = "yada yada",
_["blo"] = z
) ;
res.attr("class") = "myclass" ;
return res ;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
14. Background API Sugar Modules Overview Example Conversion
The Rcpp API : Example from RQuantLib
using namespace Rcpp;
using namespace std;
using namespace boost;
RcppExport SEXP
QL_isBusinessDay(SEXP calSexp, SEXP dateSexp) {
shared_ptr<Calendar>
pcal(getCalendar(as<string>(calSexp)));
DateVector dates = DateVector(dateSexp);
int n = dates.size();
vector<int> bizdays(n);
for (int i=0; i<n; i++) {
QuantLib::Date day( dateFromR(dates[i]) );
bizdays[i] = pcal->isBusinessDay(day);
}
return wrap(bizdays);
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
15. Background API Sugar Modules Overview Example Conversion
The Rcpp API : conversion from R to C++
Rcpp::as<T> handles conversion from SEXP to T.
template <typename T> T as( SEXP m_sexp)
throw(not_compatible) ;
T can be:
primitive type : int, double, bool, long, std::string
any type that has a constructor taking a SEXP
... that specializes the as template
... that specializes the Exporter class template
containers from the STL
more details in the Rcpp-extending vignette.
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
16. Background API Sugar Modules Overview Example Conversion
The Rcpp API : conversion from C++ to R
Rcpp::wrap<T> handles conversion from T to SEXP.
template <typename T>
SEXP wrap( const T& object ) ;
T can be:
primitive type : int, double, bool, long, std::string
any type that has a an operator SEXP
... that specializes the wrap template
... that has a nested type called iterator and member
functions begin and end
containers from the STL vector<T>, list<T>,
map<string,T>, etc ... (where T is itself wrappable)
more details in the Rcpp-extending vignette.
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
17. Background API Sugar Modules Overview Example Conversion
The Rcpp API : conversion examples
typedef std::vector<double> Vec ;
int x_ = as<int>( x ) ;
double y_ = as<double>( y_ ) ;
VEC z_ = as<VEC>( z_ ) ;
wrap( 1 ) ; // INTSXP
wrap( "foo" ) ; // STRSXP
typedef std::map<std::string,Vec> Map ;
Map foo( 10 ) ;
Vec f1(4) ;
Vec f2(10) ;
foo.insert( "x", f1 ) ;
foo.insert( "y", f2 ) ;
wrap( foo ) ; // named list of numeric vectors
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
18. Background API Sugar Modules Overview Example Conversion
The Rcpp API : implicit conversion examples
Environment env = ... ;
List list = ... ;
Function rnorm( "rnorm") ;
// implicit calls to as
int x = env["x"] ;
double y = list["y"];
// implicit calls to wrap
rnorm( 100, _["mean"] = 10 ) ;
env["x"] = 3;
env["y"] = "foo" ;
List::create( 1, "foo", 10.0, false ) ;
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
20. Background API Sugar Modules Motivation Example Contents Performance
Sugar : motivation
int n = x.size() ;
NumericVector res1( n ) ;
double x_ = 0.0, y_ = 0.0 ;
for( int i=0; i<n; i++){
x_ = x[i] ;y_ = y[i] ;
if( R_IsNA(x_) || R_IsNA(y_) ){
res1[i] = NA_REAL;
} else if( x_ < y_ ){
res1[i] = x_ * x_ ;
} else {
res1[i] = -( y_ * y_) ;
}
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
21. Background API Sugar Modules Motivation Example Contents Performance
Sugar : motivation
We missed the R syntax :
R> ifelse( x < y, x*x, -(y*y) )
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
22. Background API Sugar Modules Motivation Example Contents Performance
Sugar : motivation
We missed the R syntax :
R> ifelse( x < y, x*x, -(y*y) )
sugar brings it into C++
SEXP foo( SEXP xx, SEXP yy){
NumericVector x(xx), y(yy) ;
return ifelse( x < y, x*x, -(y*y) ) ;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
23. Background API Sugar Modules Motivation Example Contents Performance
Sugar : another example
double square( double x){
return x*x ;
}
SEXP foo( SEXP xx ){
NumericVector x(xx) ;
return sapply( x, square ) ;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
24. Background API Sugar Modules Motivation Example Contents Performance
Sugar : contents
logical operators: <, >, <=, >=, ==, !=
arithmetic operators: +, -, *, /
functions on vectors: abs, all, any, ceiling, diag,
diff, exp, head, ifelse, is_na, lapply, pmin, pmax,
pow, rep, rep_each, rep_len, rev, sapply,
seq_along, seq_len, sign, tail
functions on matrices: outer, col, row, lower_tri,
upper_tri, diag
Sugar uses Expression Templates (Blitz++, Armadillo, ...) to
achieve lazy evaluation of expressions.
More information in the Rcpp-sugar vignette.
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
25. Background API Sugar Modules Motivation Example Contents Performance
Sugar : benchmarks
expression sugar R R / sugar
any(x*y<0) 0.0008771 29.58 33721
ifelse(x<y,x*x,-(y*y)) 5.217 35.88 6.879
sapply(x,square) 0.6322 259.4 410.2
Benchmarks performed on fedora 12 / R 2.12.0 (under development) on a 2 years old dell inspiron 1525 laptop.
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
27. Background API Sugar Modules Overview R side
Modules: expose C++ to R
const char* hello( const std::string& who ){
std::string result( "hello " ) ;
result += who ;
return result.c_str() ;
}
RCPP_MODULE(yada){
using namespace Rcpp ;
function( "hello", &hello ) ;
}
R> yada <- Module( "yada" )
R> yada$hello( "world" )
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
28. Background API Sugar Modules Overview R side
Modules: expose C++ classes to R
class World {
public:
World() : msg("hello"){}
void set(std::string msg) {
this->msg = msg;
}
std::string greet() {
return msg;
}
private:
std::string msg;
};
void clearWorld( World* w){
w->set( "" ) ;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
29. Background API Sugar Modules Overview R side
Modules: expose C++ classes to R
RCPP_MODULE(yada){
using namespace Rcpp ;
class_<World>( "World" )
.method( "greet", &World::greet )
.method( "set", &World::set )
.method( "clear", &clearWorld )
;
}
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
30. Background API Sugar Modules Overview R side
Modules: on the R side
R> w <- new( yada$World )
R> w$greet()
[1] "hello"
R> w$set( "hello world")
R> w$greet()
[1] "hello world"
R> w$clear()
R> w$greet()
[1] ""
Dirk Eddelbuettel and Romain François Seamless R anc C++ Integration @ useR! 2010
31. Want to learn more ?
Check the vignettes
Questions on the Rcpp-devel mailing list
Hands-on training courses
Commercial support
Romain François romain@r-enthusiasts.com
Dirk Eddelbuettel edd@debian.org